package src.Thirteen;

import javax.swing.*;
import java.awt.*;

public class DrawIcon implements Icon {

    private int weight;
    private int height;

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public DrawIcon(int weight, int height) {
        this.weight = weight;
        this.height = height;
    }

    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) {
        g.fillOval(x,y,weight,height);
    }

    @Override
    public int getIconWidth() {
        return 0;
    }

    @Override
    public int getIconHeight() {
        return 0;
    }

    public static void main(String[] args) {
        DrawIcon icon=new DrawIcon(150,150);//初始化并且向构造方法传值
        //创建一个标签，并设置标签上的文字在标签正中间
        JLabel jl=new JLabel("测试",icon,SwingConstants.CENTER);


        JFrame jf=new JFrame();//创建一个JFrame窗口
        Container container=jf.getContentPane();//将窗口转换为容器
        container.setBackground(Color.BLUE);

        container.add(jl);
        //设置容器的外部属性
        jf.setTitle("标签的使用，创建图标");
        jf.setVisible(true);
        jf.setSize(340,400);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    }
}
